package com.heima.feign.config;

import com.heima.feign.client.TaskScheduleFeignClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.schedule.dto.TaskDto;
import com.heima.model.schedule.entity.TaskInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

@Slf4j
public class TaskScheduleFeignClientFallbackFactory implements FallbackFactory {
    @Override
    public Object create(Throwable cause) {
        return new TaskScheduleFeignClient() {
            @Override
            public ResponseResult<Long> addTask(TaskDto task) {
                log.error("任务调度服务，新增任务失败");
                return ResponseResult.okResult(null);
            }

            @Override
            public ResponseResult cancel(Long taskId) {
               log.error("任务调度服务，取消任务失败");
               return ResponseResult.okResult(null);
            }

            @Override
            public ResponseResult<TaskInfo> poll(Integer taskType, Integer priority) {
                log.error("任务调度服务，拉取任务失败");
                return ResponseResult.okResult(null);
            }
        };
    }
}
